package xul.alberti.windows;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import javax.swing.JTextField;

import xul.alberti.guardarRuta.GuardarRuta;

/**
 * 
 * @author Jaume Albertí Llompart
 *
 */

@SuppressWarnings("serial")
public class Patch extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField textField;


	/**
	 * Create the dialog.
	 */
	public Patch() {
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			JLabel lblRuta = new JLabel("Ruta:");
			lblRuta.setBounds(49, 117, 38, 15);
			contentPanel.add(lblRuta);
		}
		{
			textField = new JTextField();
			textField.setBounds(105, 115, 221, 19);
			contentPanel.add(textField);
			textField.setColumns(10);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						
						GuardarRuta assignarRuta = new GuardarRuta();
						assignarRuta.savePatch(textField.getText());
						
						
						/**
						 * Launch main JFrame
						 */
						EventQueue.invokeLater(new Runnable() {
							public void run() {
								try {
									MainWindow frame = new MainWindow();
									frame.setVisible(true);
								} catch (Exception e) {
									e.printStackTrace();
								}
							}
						});
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						// TODO Acción para el boton Cancelar "Salir de la aplicacion"
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
	
	public String getTextField(){
		return textField.getText();
	}

}
